import time as t
from selenium import webdriver
from selenium.webdriver.common.by import By
#5月29日做了更新
options = webdriver.ChromeOptions()
# 忽略证书错误
options.add_argument('--ignore-certificate-errors')
# 忽略 Bluetooth: bluetooth_adapter_winrt.cc:1075 Getting Default Adapter failed. 错误
options.add_experimental_option('excludeSwitches', ['enable-automation'])
# 忽略 DevTools listening on ws://127.0.0.1... 提示
options.add_experimental_option('excludeSwitches', ['enable-logging'])


driver = webdriver.Chrome(options=options,desired_capabilities = None)
driver.get(r'https://v.sf-express.com/web/laas/home')
# 窗口最大化
driver.maximize_window()
def login():
    # 启动浏览器
    t.sleep(2)
    # 点登陆按钮
    driver.find_element(By.CSS_SELECTOR,".top-navbar .header-rt .loginBtn").click()
    t.sleep(2)
    # 点登陆方式
    driver.find_element(By.CSS_SELECTOR,".LoginView .login-methods-title>:nth-child(2)").click()
    # 输入账号和密码
    t.sleep(1)
    driver.find_element(By.ID,"pwdLoginAccountInput").send_keys(str("15769106817"))
    t.sleep(1)
    driver.find_element(By.ID,"pwdLoginPwdInput").send_keys(str("Yw19931022"))
    t.sleep(1)
    # 勾选协议
    driver.find_element(By.CSS_SELECTOR,".login-item .pwdLoginPrivacyCheckbox .ant-checkbox-input").click()
    t.sleep(1)
    # 点登陆
    driver.find_element(By.ID,"pwdLoginBtn").click()
    t.sleep(10)
    # 进入主页，并点击查件
    # driver.find_element(By.CSS_SELECTOR,".mod-quicklink .quick-list>:nth-child(1) .label").click()
    driver.find_element(By.CSS_SELECTOR,".admin-sidebar .ant-menu-light>:nth-child(2) .ant-menu-sub>:nth-child(1)").click()
    t.sleep(3)
    # 点击旧版
    driver.find_element(By.CSS_SELECTOR,".AppPage .shun-fa-callback-btn").click()
    t.sleep(5)
    # 点击揽收后
    driver.find_element(By.CSS_SELECTOR,".global-tabnav-page .el-menu>:nth-child(2) .global-title-5").click()

    print("完全进入页面")
    t.sleep(2)

    
    

def Input_SF_ID(sf_order):
    # 填顺丰单号
    driver.find_element(By.CSS_SELECTOR,".ext-form-default .ext-item-waybillNo .ant-input").send_keys(str(sf_order))
    t.sleep(2)
    # 点查询按钮
    driver.find_element(By.CSS_SELECTOR,".ext-item-tools .ant-form-item-control-wrapper .ant-btn-primary").click()
    t.sleep(2)
    # 勾选单号
    driver.find_element(By.CSS_SELECTOR,".ant-spin-container .scroll-wrap .header-line .ant-checkbox-input").click()
    t.sleep(2)
    # 点退回
    driver.find_element(By.CSS_SELECTOR,".result-header .op-btn-block>:nth-child(3) .ant-btn").click()
    t.sleep(2)
    # 勾选协议
    driver.find_element(By.CSS_SELECTOR,".ant-modal-content .agreement .ant-checkbox-input").click()
    t.sleep(2)
    # 点确定按钮
    queding = driver.find_element(By.CSS_SELECTOR,".ant-modal-content .return-forward-footer .ant-btn-primary")
    driver.execute_script("arguments[0].style.backgroundColor = 'green';", queding)
    t.sleep(2)
    # 顺丰单号清空
    driver.find_element(By.CSS_SELECTOR,".ext-form-default .ext-item-waybillNo .ant-input").send_keys(str(""))

    print("填写完成")


if __name__ == "__main__":
    # 进入页面
    login()


    # 执行单号拦截
    Input_SF_ID("SF3102555446044")









